#ifndef FKDISPLAYREFERENT_H
#define FKDISPLAYREFERENT_H

#include <QObject>

#include <QVector3D>
#include <QColor>
#include <QMatrix4x4>

#include "fkglmodule_global.h"

class FKWorldReferent;
class FKDrawModel;

class FKGLMODULESHARED_EXPORT FKDisplayReferent : public QObject{
    Q_OBJECT
public:
    static void setWorldReferent(FKWorldReferent* world){_world=world;}
    static FKWorldReferent* worldReferent(){return _world;}

    FKDisplayReferent(QString modelName, qint32 sourceID, QObject* parent=0);
    ~FKDisplayReferent();
    const QString modelName() const;
    void setModel(const QString& modelName);
    void modelDeleted(){_model=0;}

//	void setColor(QColor color){_color=color;}
    void setPos(QVector3D pos);
//    void setOrientation(QVector3D forward, QVector3D up);
//    void setOrientation(QMatrix4x4 mat){_orientation=mat;}
    void setScale(QVector3D m);
    void setVisible(bool t){_visible=t;}

    QColor getColor() const{return _color;}
    QVector3D getPos() const{return _pos;}
//    QMatrix4x4 getOrientation() const{return _orientation;}
//    QVector3D getRequiredRotation(QVector3D targetForward, QVector3D targetUp) const;
//    QVector3D getRequiredRotation(QMatrix4x4 targetMat) const;
    QVector3D getScale() const{return _scale;}
    QMatrix4x4 getMatrix();
    bool getVisible() const{return _visible;}
    qint32 getSourceID() const{return _sourceID;}

    void setColor(QColor color){_color=color;}
    void move(double x, double y=0, double z=0){move(QVector3D(x,y,z));}
//    void rotate(double xy, double xz=0, double yz=0);
    void scale(double m){scale(QVector3D(m,m,m));}
    void scale(QVector3D scalar){setScale(_scale+scalar);}
    void show(){_visible=true;}
    void hide(){_visible=false;}

    void move(QVector3D pos);
    void rotate(float angle, QVector3D axis){rotate(QQuaternion::fromAxisAndAngle(axis,angle));}
    void rotate(const QQuaternion& q);
    void setRotation(const QQuaternion& q);

    virtual void customAnimation(){}
private:
    void calculateMatrix();
    static FKWorldReferent* _world;
    FKDrawModel* _model;
    QVector3D _pos;
    QQuaternion _rotation;
//    QMatrix4x4 _orientation;
    QMatrix4x4 _mMat;
    QVector3D _scale;
    QColor _color;
    bool _visible;
    qint32 _sourceID;
    bool _calculated;
};

#endif // FKDISPLAYREFERENT_H
